Basic SQL QueriesBy Justin Callanan |
|
Introduction Database and query basics Elements of a query Writing an SQL query Wrap-up Quiz |
Writing an SQL queryThe simplest SQL query can be written as "SELECT column_name FROM table_name". The "SELECT" statement in SQL is used for all queries. "column_name" refers to a particular column within a table, which is referred to as "table_name" in the "FROM" clause. There can be multiple column names in the query, which are are separated by commas. A common way to perform quick queries on all the data in the table is to replace the column names with a "wildcard", which automatically refers to every column contained in the table. This is written as "SELECT * FROM table_name". The most common optional clause used in basic SQL queries is the "WHERE" clause, which specifies a column and a value. This clause restricts the result set to only records in which the specified field matches the specified value. For example, one could write the query "SELECT * FROM customers WHERE name="Kelly" to return any records in the customers table with "Kelly" in the name field. < Previous | Next > |